Actual source code: aoserialize.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: aoserialize.c,v 1.3 2000/01/10 03:15:40 knepley Exp $";
3: #endif
5: #include src/dm/ao/aoimpl.h
7: #undef __FUNCT__
9: /*@
10: AOSerialize - This function stores or recreates an application ordering using a viewer for a binary file.
12: Collective on comm
14: Input Parameters:
15: + comm - The communicator for the ordering object
16: . viewer - The viewer context
17: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
19: Output Parameter:
20: . ao - The ordering
22: Level: beginner
24: .keywords: serialize, ordering
25: .seealso: VecSerialize()
26: @*/
27: int AOSerialize(MPI_Comm comm, AO *ao, PetscViewer viewer, PetscTruth store)
28: {
29: int (*serialize)(MPI_Comm, AO *, PetscViewer, PetscTruth);
30: int fd, len;
31: char *name;
32: PetscTruth match;
33: int ierr;
39: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
40: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
41: PetscViewerBinaryGetDescriptor(viewer, &fd);
43: if (store) {
45: PetscStrlen((*ao)->class_name, &len);
46: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
47: PetscBinaryWrite(fd, (*ao)->class_name, len, PETSC_CHAR, 0);
48: PetscStrlen((*ao)->serialize_name, &len);
49: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
50: PetscBinaryWrite(fd, (*ao)->serialize_name, len, PETSC_CHAR, 0);
51: PetscFListFind(comm, AOSerializeList, (*ao)->serialize_name, (void (**)(void)) &serialize);
52: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
53: (*serialize)(comm, ao, viewer, store);
54: } else {
55: PetscBinaryRead(fd, &len, 1, PETSC_INT);
56: PetscMalloc((len+1) * sizeof(char), &name);
57: name[len] = 0;
58: PetscBinaryRead(fd, name, len, PETSC_CHAR);
59: PetscStrcmp(name, "AO", &match);
60: PetscFree(name);
61: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-ordering object");
62: /* Dispatch to the correct routine */
63: if (!AOSerializeRegisterAllCalled) {
64: AOSerializeRegisterAll(PETSC_NULL);
65: }
66: if (!AOSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
67: PetscBinaryRead(fd, &len, 1, PETSC_INT);
68: PetscMalloc((len+1) * sizeof(char), &name);
69: name[len] = 0;
70: PetscBinaryRead(fd, name, len, PETSC_CHAR);
71: PetscFListFind(comm, AOSerializeList, name, (void (**)(void)) &serialize);
72: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
73: (*serialize)(comm, ao, viewer, store);
74: PetscStrfree((*ao)->serialize_name);
75: (*ao)->serialize_name = name;
76: }
78: return(0);
79: }